$(function() {
		
	initArticleBanner();
	initArticleList();
	
	/*文章轮播图*/
	function initArticleBanner(){
		var param = "";
		function callBackBanner (data){
			console.log(data);
			var html= "";
			var html1= "";
			html+= 	'<div class="mui-slider-item" v="'+data[data.length-1].id+' type="'+data[data.length-1].typeid+'"">'
					+'<img src="'+data[data.length-1].thumbnailurl+'">'
					+'<p class="mui-slider-title">'+data[data.length-1].title+'</p></div>';
			for (i in data) {
				html+= 	'<div class="mui-slider-item" v="'+data[i].id+'" type="'+data[i].typeid+'">'
						+'<img src="'+data[i].thumbnailurl+'">'
						+'<p class="mui-slider-title">'+data[i].title+'</p></div>';
				html1+=	'<div class="mui-indicator"></div>';
			}
			html+= 	'<div class="mui-slider-item" v="'+data[0].id+'" type="'+data[0].typeid+'">'
					+'<img src="'+data[0].thumbnailurl+'">'
					+'<p class="mui-slider-title">'+data[0].title+'</p></div>';
			$(".mui-slider-group").append(html);
			$(".mui-slider-indicator").append(html1);
			$($(".mui-indicator")[0]).addClass("mui-active");
		}
		articlemodule.articleBanner(param,callBackBanner);
	}
	
	/*文章轮播图*/
	var gallery = mui('.mui-slider');
	gallery.slider({
		interval:5000//自动轮播周期，若为0则不自动播放，默认为0；
	});
	$(".mui-slider-group .mui-slider-item").click(function(){
		var articleId = $(this).attr("v");
		//var typeId = $(this).attr("type");
		location.href ="article-detail.html?articleId="+articleId;
	});
	
	/*文章列表*/
	function initArticleList(){
		var param = "";
		function callBackArticle (data){
			console.log(data);
			var html= "";
			for (i in data) {
				var datetime =data[i].createtime;
				var date=datetime.substring(0,10);
				var dates=date.split("-");
				var $datetime = dates[1]+'月'+dates[2]+'日';
				if(data[i].typeid==11){
					html += '<li class="mui-table-view-cell mui-media" v="'+data[i].id+'" type="'+data[i].typeid+'">'
							+'<img class="mui-media-object mui-pull-left" src="'+data[i].thumbnailurl+'">'
							+'<div class="mui-media-body font3">'
							+'<div class="mui-ellipsis">'+data[i].title+'</div>'
							+'<p class="mui-ellipsis-2 font1">'+data[i].introduce+'</p>'
							+'<span class="create-time font1">'+$datetime+'</span></div></li>';
				}
			}
			$("#article-list").append(html);
		}
		articlemodule.articleList(param,callBackArticle);
	}


	
	$(".html-loding").hide();
	
	$("#article-list li").click(function(){
		var articleId = $(this).attr("v");
		//var typeId = $(this).attr("type");
		location.href ="article-detail.html?articleId="+articleId;
	});
	
	document.getElementById('index').addEventListener('tap',function(){
		mui.openWindow({
			url:'../../index.html',
    		id:'index',
		});
	});
	document.getElementById('message').addEventListener('tap',function(){
		mui.openWindow({
			url:'../../html/inquiry/message-list.html',
    		id:'message',
		});
	});
	document.getElementById('article').addEventListener('tap',function(){
		mui.openWindow({
			url:'../../html/article/article-list.html',
    		id:'article',
		});
	});
	document.getElementById('userCenter').addEventListener('tap',function(){
		mui.openWindow({
			url:'../../html/userCenter/user-center.html',
    		id:'userCenter',
		});
	});
});